<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>模块信息管理</title>
		<%@ include file="/WEB-INF/jsp/include.jsp"%>
		<script type="text/javascript">
		var codeFlag = 0;
		var nameFlag = 0;
		$(function(){
			setValue();
		});
		
		//获取父页面的值
		function setValue(){
		    var rows = parent.$('#tt').treegrid('getSelections');
		    var rowData = rows[0];
		    $("#menuId").val(rowData.menuId);
			$("#menuCode").val(rowData.menuCode);
			$("#menuName").val(rowData.menuName);
			$("#menuNum").val(rowData.menuNum);
			$("#menuType").val(rowData.menuType);
			$("#menuUrl").val(rowData.menuUrl);
			$('#moduleIcon').val(rowData.moduleIcon);
			$('#menuDescription').val(rowData.menuDescription);


            $("#originalCode").val(rowData.menuCode);
			//重新渲染页面
			$.parser.parse();
			    
		}
        //code 查重复
        function checkRepeatCode(value){
            var params = new Object();
            params.menuCode = value;
            params.id = $('#menuId').val();
            $.ajax({
                type: "POST",
                url: '${path}/system/module/queryByList',
                dataType: "json",
                data: params,
                success: function callback(data){
                    if(data.code=="0000"){
                        codeFlag = 0;
                        $.messager.alert('操作提示','代码不可用','info',function(){
                            $('#code')[0].focus();
                        });
                    }else{
                        codeFlag = 1;

                    }
                },
                error:function(){

                }
            });
        }

        //name,code 查重复
        function checkRepeatName(value){
            var row = parent.$('#tt').treegrid('getSelected');
            var params = new Object();
            params.menuName = value;
            params.id = $('#menuId').val();
//            if(row != null){
//                params.menuName = row.menuName;
//            }
            $.ajax({
                type: "POST",
                url: '${path}/system/module/queryByList',
                dataType: "json",
                data: params,
                success: function callback(data){
                    if(data.code=="0000"){
                        nameFlag = 0;
                        $.messager.alert('操作提示','名称不可用','info',function(){
                            $('#name')[0].focus();
                        });
                    }else{
                        nameFlag = 1;

                    }
                },
                error:function(){

                }
            });
        }
		
		
		//保存修改的数据
		function submit_Add(){
			if(codeFlag == 1){
				checkRepeatCode($('#code').val());
				return;
			}
			if(nameFlag == 1){
				checkRepeatName($('#name').val());
				return;
			}
			if (!validform("mkForm")) {
				return;
			} 
			var row = parent.$('#tt').treegrid('getSelected');
			
			var node = parent.$('#tt').treegrid('getChildren',row.code);
			if(node.length>0){
				if($('#code').val()!=row.code){
					$.messager.alert('操作提示', "非空父节点编码不可修改", 'info',function() {});
					//$.alert("default", "info", "非空父节点编码不可修改！");
					return;
				}
			}
			var param = new Object();
			if(row.sjmkDm != null){
				param.sjmkDm = row.sjmkDm;
			}
            $.ajax({
                type : "POST",
                url :'${path}/system/module/save',
                dataType : "json",
                data :$('#mkForm').serialize(),
                success : function callback(data) {
                    var analyMsg = data;
                    if (analyMsg.code != '0000') {
                        $.messager.alert('default', analyMsg.msg, 'error');

                    } else {
//                        $.messager.alert("操作提示", "模块修改成功！", "info",function() {
//                            parent.btnQuery();
//                            closeLayer();
//                        });
                        parent.btnQuery();
                        closeLayer();
                    }
                },
				error : function(data, textstatus) {
                    $.messager.alert("default", data.responseText, "error");
				}
			});
			
		}

		</script>
	</head>

  <body  style="margin:0px; padding:0px;" > 
	<%@ include file="/WEB-INF/jsp/loading.jsp" %>
	<div class="easyui-layout" fit="true" >
		<div id="AddDlgDiv" align="center">
			<form id="mkForm" method="post" >
				<table class="f_table" cellspacing="1">
					<tr>
						<td align="right" class="s_bg" style="width:100px;">
							模块代码：
						</td>
						<td align="left" style="width:210px;">
							<input type="text" id="menuCode" name="menuCode" style="width: 210px;" class="easyui-validatebox" onchange="checkRepeatCode(this.value);" data-options="required:true,tipPosition:'left'"/>
						</td>
						<td align="right" class="s_bg" style="width:100px;">
							模块名称：
						</td>
						<td align="left"  style="width: 210px;">
							<input type="text" id="menuName" name="menuName" style="width: 210px;" class="easyui-validatebox" onchange="checkRepeatName(this.value);" data-options="required:true"/>
						</td>
					</tr>
					<tr>
						<td align="right" class="s_bg">
							模块序号：
						</td>
						<td align="left" style="width:100px;">
							<input type="number" id="menuNum" name="menuNum" style="width: 210px;" class="easyui-validatebox" data-options="required:true,tipPosition:'left'"/>
						</td>
						<td align="right" class="s_bg">
							模块类型：
						</td>
						<td align="left"  style="width: 100px;">
							<input type="text" id="menuType" name="menuType" style="width: 210px;"class="easyui-validatebox" maxlength="2" data-options="required:true,tipPosition:'left'"/>
						</td>
					</tr>
					<tr>
						<td align="right" class="s_bg">
							模块 Url：
						</td>
						<td align="left" style="width:210px;" >
							<input type="text" id="menuUrl" name="menuUrl" style="width: 210px;" />
						</td>
						<td align="right" class="s_bg">
							模块图标：
						</td>
						<td align="left" style="width:210px;" >
							<input type="text" id="moduleIcon" name="moduleIcon" style="width: 210px;" />
						</td>
					</tr>
					<tr>
						<td align="right" class="s_bg">
							模块简称：
						</td>
						<td align="left" style="width:210px;" >
							<input type="text" id="menuDescription" name="menuDescription" class="easyui-validatebox" data-options="required:true" style="width: 210px;" />
						</td>
					</tr>
					
				</table>
				<input type="hidden" id="menuId" name="menuId" value="" />
				<input type="hidden" id="originalCode" name="originalCode" value="" />
				 
			</form>  
				  
			  <div align="center" style="margin-top: 15px;">
		        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submit_Add()">确定</a>
		        	<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="closeLayer();">取消</a>
       		 </div>
		</div>
	</div>
</body>
</html>
